const app = getApp()

Page({
  data: {
    oneImage: [{
      url: 'https://dss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1078861629,3747050294&fm=26&gp=0.jpg'
    }],
    oneTitle: '',
    oneContent: '',
    twoData: [{
        id: 0,
        content: '',
      },
      {
        id: 1,
        content: '',
      }
    ],
    twoActive: null,
    zimuMap: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', "I", "J", "K", "L", "M", "N", "O"]
  },
  onLoad() {},
  // 添加图片
  addImage() {
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success: (res) => {
        console.log(res);
        const img = res.tempFilePaths[0]
        this.setData({
          oneImage: [...this.data.oneImage, {
            url: img
          }]
        })
      }
    })
  },
  // 删除
  del(e) {
    const {
      index,
      item
    } = e.target.dataset
    item.splice(index, 1)
    this.setData({
      oneImage: item
    })
  },
  onInput(e) {
    this.setData({
      oneContent: e.detail.value
    })
  },
  active(e) {
    const {
      id
    } = e.target.dataset
    this.setData({
      twoActive: id
    })
  },
  twoDel(e) {
    const {
      id
    } = e.target.dataset
    const list = this.data.twoData
    list.forEach((item, index) => {
      if (item.id === id) {
        list.splice(index, 1)
      }
    });
    this.setData({
      twoData: list
    })
  },
  twoAdd(e) {
    const {
      item
    } = e.target.dataset
    const {
      twoData
    } = this.data
    this.setData({
      twoData: [
        ...twoData,
        {
          id: twoData.length,
          content: ''
        }
      ]
    })
    console.log(this.data.twoData)
  }
})